package com.jiaai.cloud.user.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jiaai.cloud.active.entity.TActivity;
import com.jiaai.cloud.base.exception.ServiceException;
import com.jiaai.cloud.base.page.CustomPage;
import com.jiaai.cloud.base.page.FrontPage;
import com.jiaai.cloud.base.util.RestResultGenerator;
import com.jiaai.cloud.user.entity.TUserLevelSettingSearch;
import com.jiaai.cloud.user.service.ITUserLevelSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户等级设置信息 前端控制器
 * </p>
 *
 * @author 佳爱网络科技
 * @since 2017-08-01
 */
@RestController
@RequestMapping("/api/manage/tUserLevelSetting")
public class TUserLevelSettingController {
    @Autowired
    private ITUserLevelSettingService itUserLevelSettingService;
    //查所有带分页
    @RequestMapping(value ="/findByAll",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
    public Object findByAll(FrontPage page, String name) throws ServiceException {
        try {
            EntityWrapper wrapper=new EntityWrapper();
            if(name==null){
                return RestResultGenerator.genSuccessResult(itUserLevelSettingService.selectPage(page.getPagePlus(),wrapper));
            }
            wrapper.like("name",name);
            return RestResultGenerator.genSuccessResult( itUserLevelSettingService.selectPage(page.getPagePlus(),wrapper));
            } catch (Exception e) {
            throw new ServiceException("查询失败", e.getMessage());
        }
    }

    //删
    @RequestMapping(value ="/deleteId/{id}", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public Object deleteId(@PathVariable("id") Integer id) throws ServiceException {
        try {
            itUserLevelSettingService.deleteById(id);
            return RestResultGenerator.genSuccessResult();
        } catch (Exception e) {
            throw new ServiceException("删除失敗", e.getMessage());
        }
    }

}
